/**
 * Notes: 门禁控制模块控制器 - 宠物门店预约小程序
 * Date: 2025-01-27 
 */

const BaseController = require('./base_controller.js');
const AccessService = require('../service/access_service.js');

class AccessController extends BaseController {

	/**
	 * 请求扫码开门
	 */
	async openDoor() {
		this.ensureAuthenticatedForWrite();
		// 数据校验
		let rules = {
			storeId: 'string|min:1|max:50|name=门店ID',
			topic: 'string|min:1|max:200|name=MQTT主题'
		};

		let input = this.validateData(rules);

		let service = new AccessService();
		return await service.requestOpenDoor(this._userId, input.storeId, input.topic);
	}
}

module.exports = AccessController;
